<?php
    class Default_Model_Category extends Zend_Db_Table_Abstract
    {
        protected $_db;

        public function __construct()
        {
            $this->_db = Zend_Registry::get('db');
        }

        public function listItem($locale)
        {
            $sql = $this->_db->select()
                            ->from('category AS c')
                            ->join('category_language AS cl', 'cl.category_id = c.id', array('cl.name'))
                            ->join('language AS l', 'l.id = cl.language_id', null)
                            ->where('c.status = ?', 1)
                            ->where('l.locale = ?', $locale)
                            ->order('c.id ASC');
            $result = $this->_db->fetchAll($sql);
            return $result;
        }

        public function getCategoryName($category_id, $locale)
        {
            $sql = $this->_db->select()
                            ->from('category_language AS cl', array('name'))
                            ->join('language AS l', 'l.id = cl.language_id', null)
                            ->where('cl.category_id = ?', $category_id)
                            ->where('l.locale = ?', $locale);
            $result = $this->_db->fetchOne($sql);
            return $result;
        }
    }
